package persistences;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;



import services.trainingplan.MajorPlan;
import util.DBUtil;
import DTO.TrainingPlanDTO;

public class TrainingPlanDAO {
	private static Connection conn;
	public static int Add(TrainingPlanDTO trainingPlan,MajorPlan majorPlan){
		String sql="insert into plan_info"
	           +"(planYear,name,startDate,endDate,majorName,trainPurpose,trainContent,classHours,teacher)"
			  +"value(?,?,?,?,?,?,?,?,?)";
		conn=DBUtil.getConnection();
		PreparedStatement ps=null;
		try{
			ps=conn.prepareStatement(sql);
			ps.setString(1,trainingPlan.getPlanYear());
			ps.setString(2,trainingPlan.getName());
			ps.setString(3,trainingPlan.getStarDate());
			ps.setString(4,trainingPlan.getEndDate());
			ps.setString(5,majorPlan.getMajorName());
			ps.setString(6,majorPlan.getTrainingPurpose());
			ps.setString(7,majorPlan.getTrainingContent());
			ps.setString(8,majorPlan.getClassHours());
			ps.setString(9,majorPlan.getTeacher());
			return ps.executeUpdate();
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			if(ps!=null){
				try{
					ps.close();
				}catch(SQLException e){
					e.printStackTrace();
				}
			}
	    }
		return -1;
	}

}
